export const useMainStore = defineStore(
  'main',
  () => {
    const userProfile = ref<UserProfiles>()

    const currentPath = ref<CurrentPath>()

    const routeTags = ref<RouteTag[]>([])

    const menus = ref<Menu[]>()

    const firstChildMenu = ref<Menu>()

    const contextShow = ref<boolean>(true)

    const collapse = ref<boolean>(false)

    const hasPerm = (premKey: string): boolean => {
      const permissionsArray = userProfile.value?.permissions.filter((p) => {
        return p === premKey
      })
      return permissionsArray?.length !== 0
    }

    return {
      userProfile,
      currentPath,
      routeTags,
      menus,
      firstChildMenu,
      contextShow,
      collapse,
      hasPerm
    }
  },
  {
    persistedState: {
      storage: sessionStorage
    }
  }
)
